/*
 * 类名称:ShopsServiceImpl.java
 * 包名称:com.platform.service.impl
 *
 * 修改履历:
 *     日期                       修正者        主要内容
 *     2019-08-28 11:44:24        lipengjun     初版做成
 *
 * Copyright (c) 2019-2019 微同科技
 */
package com.platform.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.platform.utils.Query;
import com.platform.utils.QueryPlus;
import com.platform.dao.ShopsDao;
import com.platform.entity.ShopsEntity;
import com.platform.service.ShopsService;
import com.platform.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 商铺表Service实现类
 *
 * @author sunkaichun
 * @date 2019-08-28 11:44:24
 */
@Service("shopsService")
public class ShopsServiceImpl extends ServiceImpl<ShopsDao, ShopsEntity> implements ShopsService {

    @Autowired
    private ShopsDao shopsDao;

    @Override
    public List<ShopsEntity> queryAll(Map<String, Object> params) {
        return baseMapper.queryAll(params);
    }

    @Override
    public Page queryPage(Map<String, Object> params) {
        //排序
        params.put("sidx", "T.id");
        params.put("asc", false);
        Page<ShopsEntity> page = new QueryPlus<ShopsEntity>(params).getPage();
        return page.setRecords(baseMapper.selectShopsPage(page, params));
    }

    @Override
    public boolean add(ShopsEntity shops) {
        Long userId = ShiroUtils.getUserId();
        shops.setCreateTime(new Date());
        shops.setCreateUserId(userId);
        return this.save(shops);
    }

    @Override
    public boolean update(ShopsEntity shops) {
        Long userId = ShiroUtils.getUserId();
        shops.setUpdateTime(new Date());
        shops.setUpdateUserId(userId);
        return this.updateById(shops);
    }

    @Override
    public boolean delete(Integer id) {
        return this.removeById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteBatch(Integer[] ids) {
        return this.removeByIds(Arrays.asList(ids));
    }

    @Override
    public List<ShopsEntity> queryByAreaId(Integer buildingId) {
        QueryWrapper<ShopsEntity> wrapper = new QueryWrapper<>();
        wrapper.eq("building_id",buildingId).eq("status",0);
        return baseMapper.selectList(wrapper);
    }

    @Override
    public int queryTotal(Map<String, Object> params) {
        Query query = new Query(params);
        return baseMapper.queryTotal(query);
    }

    @Override
    public List<ShopsEntity> queryList(Query query) {
        return shopsDao.queryList(query);
    }


}
